<template>
  <div class="app-foundation-login">
    <form class="login-form">
      <div class="title-container">
        <h3 class="title">系统登录</h3>
      </div>
      <div class="form-item">
        <label class="form-item-label">用户名</label>
        <div class="form-item-el">
          <input v-model="loginFrom.name" type="text" class="form-input" />
        </div>
      </div>
      <div class="form-item">
        <label class="form-item-label">密码</label>
        <div class="form-item-el">
          <input v-model="loginFrom.password" type="password" class="form-input" />
        </div>
      </div>
      <div v-if="false" class="form-msg">登录失败：用户名或密码不正确</div>
      <button type="button" @click="loginIn()" class="form-button">登录</button>
    </form>
  </div>
</template>

<script>
import { reactive } from '@vue/reactivity';
import { useStore } from 'vuex'
import { useRouter, useRoute } from "vue-router";

import { actions } from "@/micros"
import { onMounted } from '@vue/runtime-core';

export default {
  components: {

  },
  props: {

  },
  setup() {
    const Store = useStore()
    const Router = useRouter()

    const loginFrom = reactive({
      name: 'admin',
      password: '123456',
    })

    // onMounted(() => {
    //   actions.onGlobalStateChange((state) => {
    //     // state: 变更后的状态; prevState: 变更前的状态
    //     console.log("主应用观察者：状态改变", state);
    //   })
    // })

    let loginIn = () => {
      let token = loginFrom.name + "&" + loginFrom.password
      Store.commit("setToken", token)

      //   微应用 通信
      actions.setGlobalState({ globalToken: token })

      console.log("token", Store.state.token)
      Router.push("/")
    }

    return { loginFrom, loginIn }
  }
}
</script>

<style lang="scss" scoped>
.app-foundation-login {
  overflow: hidden;
  min-height: 100%;
  width: 100%;
  background-color: #2d3a4b;
  font-size: 14px;
  .login-form {
    box-sizing: border-box;
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }
  .title-container {
    position: relative;
  }
  .title {
    font-size: 26px;
    color: #eee;
    margin: 0 auto 40px auto;
    text-align: center;
    font-weight: 400;
  }
  .form-item {
    margin-bottom: 22px;
    border: 1px solid hsla(0,0%,100%,.1);
    background: rgba(0,0,0,.1);
    border-radius: 5px;
    color: #454545;
  }
  .form-item-label {
    box-sizing: border-box;
    position: relative;
    float: left;
    margin-right: 4px;
    padding: 12px 12px;
    width: 68px;
    height: 44px;
    line-height: 20px;
    color: #999;
    text-align: justify;
    text-justify: distribute-all-lines; // 这行必加，兼容ie浏览器
    text-align-last: justify;
    &:after {
      content: "";
      position: absolute;
      right: 0;
      top: 50%;
      width: 1px;
      height: 14px;
      margin-top: -6px;
      background: #666
    }
  }
  .form-item-el {
    overflow: hidden;
  }
  .form-input {
    box-sizing: border-box;
    width: 100%;
    height: 46px;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 12px 5px;
    line-height: 20px;
    color: #fff;
    caret-color: #fff;
    outline: none;
    -webkit-appearance: none;
  }
  .form-button {
    box-sizing: border-box;
    display: block;
    margin-bottom: 30px;
    padding: 12px 20px;
    width: 100%;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    text-align: center;
    outline: none;
    margin: 0;
    transition: .4s;
    font-weight: 400;
    user-select: none;
    font-size: 14px;
    border-radius: 4px;
    color: #fff;
    background-color: #1890ff;
    border: 1px solid #1890ff;
    outline: none;
    -webkit-appearance: none;
    &:focus, &:hover {
      background: #46a6ff;
      border-color: #46a6ff;
      color: #fff;
    }
  }
  .form-msg {
    line-height: 28px;
    color: #F66D6F;
  }
}
</style>
